package com.luojialong.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.luojialong.constant.PageSelectSort;
import org.apache.commons.lang3.StringUtils;

public class MyStringUtils {

    public final static CharSequence[] SQL_SORT_RULES = {"=", "(", ")", " "};


    public static boolean isContainAnyOne(CharSequence[] rule,String field) {
        if (StringUtils.isNotBlank(field)) {
            return false;
        }
        return !StringUtils.containsAny(field,SQL_SORT_RULES);
    }

    public static<T> void setWrapper(QueryWrapper<T> queryWrapper,String sortField,String sortOrder) {
        queryWrapper.orderBy(isContainAnyOne(SQL_SORT_RULES,sortField),sortOrder.equals(PageSelectSort.SORT_ORDER_ASC),sortField);
    }
}
